using UnityEngine;
using System.Collections;

public class CharacterDrop  : MonoBehaviour
{
	private bool canDrop;
	private bool ready;
	private CharacterManager player;

    private GameObject data;


	void Start()
	{
        data = GameObject.FindGameObjectWithTag("_Manager");
		canDrop = true;
		player = gameObject.GetComponent<CharacterManager>();	
	}
	
	void Update () 
	{
		#if UNITY_STANDALONE || UNITY_WEBPLAYER
		
			if((Input.GetButtonDown("Jump") || Input.GetKeyDown(KeyCode.LeftControl)) && canDrop && !player.specialCube)
			{
				// Contar numero de drops e testar unlock do achievement.
				
				AchievementItem ach = AchieveStorage.getInstance.getByName("Color Shooter");
				ach.Add();
			
			
				if(ach.Teste())
				{
	            	AchieveStorage.getInstance.UnlockAchieve(ach, Camera.mainCamera);
				}
				
				data.SendMessage("addDrop",SendMessageOptions.DontRequireReceiver);
				
				player.getColorManager().DropColor();
				StartCoroutine("restoreDrop");
			}
		
		#endif
		
		#if UNITY_ANDROID
		
			if(Input.touchCount == 1 && ready && canDrop && !player.specialCube)
			{
				ready = false;
				player.getColorManager().DropColor();
				StartCoroutine("restoreDrop");
			}
			
			if(Input.touchCount == 0 && !ready)
			{
				ready = true;
			}
		
		#endif
	}

	IEnumerator restoreDrop()
	{
		canDrop = false;
		yield return new WaitForSeconds(0.2f);
		canDrop = true;
	}
}
